import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import './assets/global.css'

//引入axios
import axios from "axios";
//引入解析jwt-decode
import jwtDecode from "jwt-decode";

Vue.config.productionTip = false

axios.interceptors.request.use(config=>{
  var token = window.sessionStorage.getItem("token");
  if (token) {
    config.headers.token = token;
  }
  return config;
})
Vue.prototype.$http=axios


router.beforeEach((to,from,next)=>{
  var path = to.path;
  if (path === "/login") {
    return next();
  }
  var token = window.sessionStorage.getItem("token");
  if (token) {
    const decode = jwtDecode(window.sessionStorage.getItem("token"))
    window.sessionStorage.setItem("imgUrl",decode.imgUrl)
    return next();
  }
  return next("/login");
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
